package com.yxkj.syh.app.huarong.adps;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.recyclerview.widget.RecyclerView;

import com.syh.app.basic.base.BaseAdp;
import com.yxkj.syh.app.huarong.BR;
import com.yxkj.syh.app.huarong.R;
import com.yxkj.syh.app.huarong.bean.PayOrderInfo;

/**
 * 创建者：SYH
 * 时间：2020/5/25 16:16
 * 编辑者：SYH、
 * 标签：
 * 补充说明：
 */
public class PayOrderListAdp extends BaseAdp<PayOrderInfo> {
    private OnViewClick mOnViewClick;

    @Override
    protected RecyclerView.ViewHolder createYourViewHolder(@NonNull ViewGroup parent, int viewType) {
        if (viewType == 0) {
            ViewDataBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_pay_order_list, parent, false);
            View view = binding.getRoot();
            view.setTag(binding);
            return new ViewHolder(view);
        } else {
            ViewDataBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_pay_order_list_end, parent, false);
            View view = binding.getRoot();
            view.setTag(binding);
            return new ViewHolder(view);
        }
    }

    @Override
    public int getItemViewType(int position) {

        if (mData.size() > 0) {
            if (position == mData.size() - 1) {
                return 1;
            }
        }

        return super.getItemViewType(position);
    }

    @Override
    protected void bindYourViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        if (mOnViewClick != null) {
            holder.itemView.setOnClickListener(v -> {
                mOnViewClick.onItem(mData.get(position));
            });
            ((ViewHolder) holder).tvReceiveGoods.setOnClickListener(v -> {
                mOnViewClick.onConfirmReceive(mData.get(position));
            });

        }
        ViewDataBinding binding = (ViewDataBinding) holder.itemView.getTag();
        binding.setVariable(BR.payOrderInfo, mData.get(position));
        binding.executePendingBindings();


    }

    public void setOnViewClick(OnViewClick onViewClick) {
        this.mOnViewClick = onViewClick;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvReceiveGoods;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvReceiveGoods = itemView.findViewById(R.id.tvReceiveGoods);
        }
    }

    public interface OnViewClick {
        void onItem(PayOrderInfo payOrderInfo);

        void onConfirmReceive(PayOrderInfo payOrderInfo);
    }

}
